package pratise;

public class RemoveElement {
    public static int removeElement(int[] nums, int val) {
        int slow = 0;//表示删除后有效长度
        int fast = 0;//表示需要判断的下标
        while(fast < nums.length) {
            if(nums[fast] != val) {
                nums[slow++] = nums[fast];
            }
            fast++;
        }
        return slow;
    }

    public static void main(String[] args) {
        int[] arr = {0,1,2,2,3,0,4,2};
        int val = 2;
        int len = removeElement(arr, val);
        for (int i = 0; i < len; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
